<!--
*
* Copyright 2015 HISP Tanzania
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301, USA.
*
* @since 2015
* @author Joseph Chingalo profschingalo@gmail.com>
*
*
-->
<ion-header>

  <ion-navbar [color]="(colorSettings$ |async).colorAttributes.main">
    <ion-title>
      <span [translate]="'Settings'"></span>
    </ion-title>
  </ion-navbar>

</ion-header>


<ion-content>

  <ion-grid>

    <div *ngIf="isLoading">
      <loading [loadingMessage]="loadingMessage" [loadingSize]="'large'"></loading>
    </div>
    <div *ngIf="!isLoading">
      <div class="item-card" *ngFor="let settingContent of settingContents;trackBy: trackByFn">
        <ion-row (tap)="toggleSettingContents(settingContent)">
          <ion-col col-11>
            <img class="side-menu-icon" [src]="settingContent.icon" />&nbsp;&nbsp;
            <span ion-text [color]="(isSettingContentOpen[settingContent.id]) ?'current' : 'font-color'" [translate]="settingContent.name"></span>
          </ion-col>
          <ion-col col-1 item>
            <div style="text-align: center;">
              <ion-icon [color]="(isSettingContentOpen[settingContent.id]) ?'current' : 'font-color'" *ngIf="!(isSettingContentOpen[settingContent.id])"
                name="ios-arrow-down" item-right></ion-icon>
              <ion-icon [color]="(isSettingContentOpen[settingContent.id]) ?'current' : 'font-color'" *ngIf="(isSettingContentOpen[settingContent.id])"
                name="ios-arrow-up" item-right></ion-icon>
            </div>
          </ion-col>
        </ion-row>
        <div class="updateManagerContents" *ngIf="(isSettingContentOpen[settingContent.id])">
          <hr>

          <div *ngIf=" settingContent.id == 'appSettings'">
            <app-settings [currentLanguage]="currentLanguage" (onUpdateCurrentLanguage)="updateCurrentLanguage($event)"
              [translationCodes]="translationCodes"></app-settings>
          </div>

          <div *ngIf="settingContent.id == 'synchronization'">
            <div *ngIf="settingObject.synchronization">
              <synchronization-settings [colorSettings]="colorSettings$ |async" [(settingObject)]="settingObject"
                (onUpdateSyncSetting)="updateAutoSyncSetting($event,settingContent)"></synchronization-settings>
            </div>
          </div>

          <div *ngIf="settingContent.id == 'entryForm'">
            <div *ngIf="settingObject.entryForm">
              <entry-form-settings [colorSettings]="colorSettings$ |async" [(settingObject)]="settingObject"
                (onUpdateDataEntrySettings)="applySettings(settingContent)"></entry-form-settings>
            </div>
          </div>

          <div *ngIf="settingContent.id == 'barcode'">
            <div *ngIf="settingObject.barcode">
              <barcode-settings [colorSettings]="colorSettings$ |async" [(settingObject)]="settingObject"
                (onUpdateBarcodeSettings)="applySettings(settingContent)"></barcode-settings>
            </div>
          </div>

        </div>
      </div>
    </div>

  </ion-grid>

</ion-content>
